home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / ccompile.zip / LATER.C < prev    next >
C/C++ Source or Header  |  1988-11-29  |  2KB  |  73 lines

  1. /*    LATER.C        --    Exit with a 1 if any file has a higher create
  2.                     date than the last or if the last file does not exist.
  3.                     A 2 is returned if any other files do not exist.
  4.                     Later only works on MS-DOS V2.0.
  5.  
  6.                     A>LATER FILE1.C FILE1.O
  7.                     Later will set completion code to 1 if FILE1.C was
  8.                     created after FILE1.O.
  9.  
  10.                     A>LATER FILE1.C FILE1.H FILE1.O
  11.                     Later will set completion code to 1 if FILE1.C or
  12.                     FILE1.H was created after FILE1.O.    */
  13.  
  14.  
  15.  
  16. main(argc,argv)
  17.     int  argc;
  18.     char *argv[]; {
  19.  
  20.     unsigned ifile,ofile,i;
  21.     long odate,dateof();
  22.  
  23.     puts("LATER V1.0      ");
  24.  
  25.     if (argc < 3 ) {
  26.         puts("need two or more arguments");
  27.         exit(0);
  28.         }
  29.  
  30.     if ((ofile=open(argv[argc-1],0)) == -1)
  31.         exit(1);    /* the last file does not exist    */
  32.  
  33.     odate=dateof(ofile);
  34.     close(ofile);
  35.  
  36. /*    for each file see if it is later than the last one    */
  37.  
  38.     for (i=1; i < argc-1; i++) {
  39.         if ((ifile=open(argv[i],0)) == -1) {
  40.             puts(argv[i]);
  41.             puts(" does not exist");
  42.             exit(2);    /* an early file does not exist    */
  43.             }
  44.         if (dateof(ifile) > odate) exit(1);    /* found a later file */
  45.         close(ifile);
  46.         }
  47.  
  48. /*    none of the files are later. set completion code of zero    */
  49.  
  50.     exit(0);
  51.     }
  52.  
  53.  
  54. /*    return a long encoding the date and time of a file    */
  55.  
  56. long dateof(fil)
  57.     int  fil; {
  58.     static long ret_dt;
  59.  
  60. #asm
  61.     mov        bx,[bp+4]                ;file handle is here. only argument.
  62.     and        bx,0ffh                    ;low byte of file id is MS-DOS handle.
  63.     mov        al,0                    ;code to retrieve date and time.
  64.     mov        ah,57h                    ;dos code for get file date and time.
  65.     int        21h                        ;call dos.
  66.     mov        word dateof_ret_dt_+2,dx;store date in high word of ret_dt.
  67.     mov        word dateof_ret_dt_,cx    ;store time in low word of ret_dt.
  68.                                     ;note: "dateof_" is added to name
  69.                                     ;because ret_dt is static.
  70. #
  71.     return ret_dt;
  72.     }
  73.